<template>
  <div :style="{ background: $store.state.app.themeColor }" class="header-wrap">
    <div class="custom-shape-divider-top">
      <svg
        data-name="Layer 1"
        xmlns="http://www.w3.org/2000/svg"
        viewBox="0 0 1200 120"
        preserveAspectRatio="none"
      >
        <path
          d="M0,0V46.29c47.79,22.2,103.59,32.17,158,28,70.36-5.37,136.33-33.31,206.8-37.5C438.64,32.43,512.34,53.67,583,72.05c69.27,18,138.3,24.88,209.4,13.08,36.15-6,69.85-17.84,104.45-29.34C989.49,25,1113-14.29,1200,52.47V0Z"
          opacity=".25"
          class="shape-fill"
        ></path>
        <path
          d="M0,0V15.81C13,36.92,27.64,56.86,47.69,72.05,99.41,111.27,165,111,224.58,91.58c31.15-10.15,60.09-26.07,89.67-39.8,40.92-19,84.73-46,130.83-49.67,36.26-2.85,70.9,9.42,98.6,31.56,31.77,25.39,62.32,62,103.63,73,40.44,10.79,81.35-6.69,119.13-24.28s75.16-39,116.92-43.05c59.73-5.85,113.28,22.88,168.9,38.84,30.2,8.66,59,6.17,87.09-7.5,22.43-10.89,48-26.93,60.65-49.24V0Z"
          opacity=".5"
          class="shape-fill"
        ></path>
        <path
          d="M0,0V5.63C149.93,59,314.09,71.32,475.83,42.57c43-7.64,84.23-20.12,127.61-26.46,59-8.63,112.48,12.24,165.56,35.4C827.93,77.22,886,95.24,951.2,90c86.53-7,172.46-45.71,248.8-84.81V0Z"
          class="shape-fill"
        ></path>
      </svg>
    </div>
    <div class="header-left dinlt-mid-flex-container">
      <div class="sidebar-info">
        <span class="title">One Piece</span>
        <span class="nav-separator" />
        <span>Let data dance</span>
      </div>
    </div>
    <div
      v-if="userName || env"
      class="header-right dinlt-between-flex-container"
    >
      <el-tooltip
          :content="questionDom"
          raw-content
          placement="top">
        <el-icon  style="color: #409EFF"><QuestionFilled /></el-icon>
      </el-tooltip>
      <div v-if="false" class="nav-item">
        <el-dropdown style="color: #fff" @command="changeObject">
          <div class="el-dropdown-link header-flex">
            <img
              v-show="false"
              style="margin-right: 5px"
              width="20"
              :src="countryImage"
            />
            {{ headerEnvironment }}
            <i class="el-icon-arrow-down el-icon--right"></i>
          </div>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item command="us">
              <div class="header-flex" style="height: 35px">
                <img
                  v-show="false"
                  style="margin-right: 5px"
                  width="20"
                  src=""
                />
                {{ $t('index.headerUS') }}
              </div></el-dropdown-item
            >
            <el-dropdown-item v-if="false" command="de">
              <div class="header-flex" style="height: 35px">
                <img
                  style="margin-right: 5px"
                  width="20"
                  src=""
                />
                {{ $t('index.headerDE') }}
              </div>
            </el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
      <el-divider direction="vertical"></el-divider>
<!--      <el-color-picker-->
<!--        v-model="color"-->
<!--        size="mini"-->
<!--        show-alpha-->
<!--        :predefine="predefineColors"-->
<!--      />-->
      <el-dropdown
        placement="bottom"
        style="color: #fff"
        @command="changeLanguage"
      >
        <el-button style="border: none;outline: none;" link class="nav-item">
          {{ $t('index.headerLang') }}
        </el-button>
        <template #dropdown>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="zh">中文</el-dropdown-item>
          <el-dropdown-item command="en">English</el-dropdown-item>
        </el-dropdown-menu>
        </template>
      </el-dropdown>
      <the-full-screen v-model="isFullScreen"></the-full-screen>
      <!--      <the-theme-switcher></the-theme-switcher>-->
      <el-dropdown
        placement="bottom"
        style="color: #fff"
        @command="handleCommand"
      >
        <el-button style="border: none;outline: none;" link>
          {{ userName || '' }}
          <el-icon class="el-icon--right">
            <arrow-down />
          </el-icon>
        </el-button>
        <template #dropdown>
        <el-dropdown-menu slot="dropdown">
          <!--          <el-dropdown-item command="message">消息中心</el-dropdown-item>-->
          <!--          <el-dropdown-item command="ownerCenter">个人中心</el-dropdown-item>-->
          <el-dropdown-item command="logout">Logout</el-dropdown-item>
        </el-dropdown-menu>
          </template>
      </el-dropdown>
      <the-avator src="https://pic4.zhimg.com/7be980a0f_xll.jpg"></the-avator>
    </div>
  </div>
</template>

<script>
import rgbHex from 'rgb-hex'
import TheFullScreen from './MainHeader/TheFullScreen.vue'
import TheAvator from './MainHeader/TheAvator.vue'
import { mapActions } from 'vuex'
import { getLocal } from '@/utils/navigation'

export default {
  name: 'MainHeader',
  components: { TheFullScreen, TheAvator },
  data() {
    let that = this
    return {
      questionDom:
        '<p>If you have any questions about the system,</p> <p>please contact the administrator: </p><p>sevenzhang@prox.com</p>',
      env: window.location.href.indexOf('lego-test') > -1,
      isFullScreen: false,
      langCode: 'en',
      color: that.$store.state.app.themeColor,
      predefineColors: [
        '#44465c',
        '#ff4500',
        '#ff8c00',
        '#ffd700',
        '#90ee90',
        '#00ced1',
        '#1e90ff',
        '#c71585',
        'rgba(255, 69, 0, 0.68)',
        'rgb(255, 120, 0)',
        'hsv(51, 100, 98)',
        'hsva(120, 40, 94, 0.5)',
        'hsl(181, 100%, 37%)',
        'hsla(209, 100%, 56%, 0.73)',
        '#c7158577',
      ],
    }
  },
  computed: {
    headerEnvironment() {
      let result = ''
      switch (this.$store.state.app.environment) {
        case 'us':
          result = this.$t('index.headerUS')
          break
        case 'de':
          result = this.$t('index.headerDE')
          break
        default:
          result = 'SIM'
          break
      }
      return result
    },
    countryImage() {
      let result = ''
      switch (this.$store.state.app.environment) {
        case 'us':
          result =
            ''
          break
        case 'de':
          result =
            ''
          break
        default:
          result =
            ''
          break
      }
      return result
    },
    avator() {
      return this.$store.state.user.avator
    },
    userName() {
      return 'sevenzhang'
      // return this.$store.state.user.userName
    },
  },
  created() {
    let color = getLocal('dintTheme')
    if (color === '') {
      this.$store.commit('setTheme', '#409EFF')
      // this.$theme.changeTheme('rgb(255, 120, 0)')
    }
  },
  mounted() {},
  watch: {
    color: function (val) {
      // 切换element主题色
      let primaryColor = `#${rgbHex(val).substr(0, 6)}`
      // this.$theme.changeTheme(primaryColor)
      this.$store.commit('setTheme', primaryColor)
    },
  },
  methods: {
    ...mapActions(['handleLogOut']),
    handleHeaderShow(status) {
      this.$store.commit('setIsShowHeader', status)
    },
    changeObject(e) {
      let url = ''
      switch (e) {
        case 'us':
          url = 'product'
          break
        case 'sim':
          url = 'test'
          break
        // case 'legode':
        //   url = 'testde'
        //   break
        // case 'legous':
        //   url = 'product'
        //   break
        // case 'dfarede':
        //   url = 'testdf'
        //   break
        // case 'dfare':
        //   url = 'testdf'
        //   break
        default:
          break
      }
      window.location.replace(url)
    },
    logout() {
      window.location.replace(this.$store.state.app.logoutUrl)
      // this.handleLogOut().then(() => {
      //   this.$router.push({
      //     name: 'Login',
      //   })
      // })
    },
    changeLanguage(e) {
      this.$i18n.locale = e
      this.$store.commit('setLocal', e)
    },
    message() {},
    ownerCenter() {},
    handleCommand(name) {
      switch (name) {
        case 'logout':
          this.logout()
          break
        case 'message':
          this.message()
          break
        case 'ownerCenter':
          this.message()
          break
      }
    },
  },
}
</script>

<style lang="less">
.el-dropdown-menu__item {
  font-size: 16px !important;
}
.header-flex {
  display: flex;
  flex-wrap: nowrap;
  justify-content: center;
  align-items: center;
}
.header-wrap {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 100%;
  box-shadow: 0 4px 10px 0 rgba(0, 0, 0, 0.15);
  padding: 0 10px;
  text-align: right;
  .custom-shape-divider-top {
    position: absolute;
    top: 0;
    left: 0;
    height: 50px;
    width: 100%;
    overflow: hidden;
    line-height: 0;
  }
  .custom-shape-divider-top svg {
    position: relative;
    display: block;
    width: calc(100% + 1.3px);
    height: 110px;
  }
  .el-color-picker__trigger {
    border: none !important;
  }
  .el-color-picker__color {
    border: 1px solid rgba(255, 255, 255, 0.47) !important;
  }
  .el-header {
    color: #fff;
    line-height: 60px;
    padding: 0;
  }

  .header-left {
    width: 205px;
    height: 100%;
    position: absolute;
    left: 10px;
  }
  .header-right {
    position: absolute;
    right: 10px;
    height: 100%;
    width: fit-content;
    cursor: pointer;
    .nav-item {
      height: 100%;
      line-height: 48px;
    }
    .nav-item:hover {
      border-bottom: 1px solid;
    }
    span {
      color: white;
    }
    div {
      color: white;
    }
  }
  .sidebar-info {
    display: block;
    color: #fff;
    height: 50px;
    line-height: 50px;
    // font-family: Avenir, Helvetica Neue, Arial, Helvetica, sans-serif;
    span:nth-child(1) {
      font-size: 16px;
      font-family: Avenir, Helvetica;
      font-weight: 700;
      vertical-align: middle;
      margin: 0 4px;
    }
    span:nth-child(2) {
      border-top: 2px solid transparent;
      border-bottom: 2px solid transparent;
      height: 24px;
      border-left: 1px solid #ccd8dc;
      line-height: 22px;
      vertical-align: middle;
      display: inline-block;
    }
    span:nth-child(3) {
      font-size: 12px;
      transform: scale(0.8);
      margin: 0 4px;
      vertical-align: middle;
    }
  }
}
</style>
